import React, { Component } from 'react'
import store from '../../redux/store'
// import { addAction, minusAction, asyncAction } from '../../redux/count_action'
export default class Count extends Component {

    add = () => {
        const { value } = this.selectNumber
        // 通知redux改数据。【*1 强制类型转换】
        // store.dispatch(addAction(value * 1))
        this.props.jia(value * 1)
    }
    minus = () => {
        const { value } = this.selectNumber
        // 通知redux改数据
        // store.dispatch(minusAction(value * 1))
        this.props.jian(value * 1)
    }
    addOdd = () => {
        const { value } = this.selectNumber
        // const count = store.getState()
        if (this.props.count % 2 != 0) this.props.jia(value * 1)
    }
    addAsync = () => {
        const { value } = this.selectNumber
        // const count = store.getState()
        // store.dispatch(asyncAction(value * 1,500))
        this.props.asyncJia(value * 1,1000)
    }
    render() {
        console.log('CountUI组件',this.props);

        return (
            <div>
                <h1>当前求和为：{this.props.count}</h1>
                <select ref={c => this.selectNumber = c}>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
                <button onClick={this.add}>+</button>
                <button onClick={this.minus}>-</button>
                <button onClick={this.addOdd}>当前求和为奇数在加</button>
                <button onClick={this.addAsync}>异步加</button>
            </div>
        )
    }
}
